<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class First_lib {

	function object_pair_demand_sql($data ,$_start_num , $load_count) {

		$where_flag = TRUE;
		$where = '';
		$excerpt_array = array();
		$_select_field_name = array();
		
		$__area_place1 			=	array();//區域－路段
		$__area_place2 			=	array();//區域－路段
		$__area_place3 			=	array();//區域－路段
		
		$__area_number1 			=	array();//面積
		$__area_number2 			=	array();//面積
		$__area_number3 			=	array();//面積
		
		$__object_type1			=	array();
		$__object_type2			=	array();
		
		
		$__other1				=	array();
		$__other2				=	array();
		$__other3				=	array();
		$__other4				=	array();
		$__other5				=	array();
		
		$__price1				=	array();
		$__price2				=	array();
		
		$__house_and1			=	array();
		$__house_and2			=	array();
		$__house_or1				=	array();
		$__house_or2				=	array();
		$__house_or3				=	array();
		
		
		
		//print_r($data);
		
		$_type_rent = !empty($data["type_rent"])?$data["type_rent"]:'';
		$_type_sale = !empty($data["type_sale"])?$data["type_sale"]:'';
		
		
		foreach ($data as $name => $value) {

			if ($value != '' AND $value != '0.00' AND $value != '0') {

				//物件類型
				if ($name == "type_sale") {
					//售

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " OR ";
					}

					$where .= "    `" . 'type_sell' . "` = '" . $value . "' ";
					$__object_type1[]="    `" . 'type_sell' . "` = '" . $value . "' ";
				}
				if ($name == "type_rent") {
					//租

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " OR ";
					}

					$where .= "    `" . 'type_rent' . "` = '" . $value . "' ";
					$__object_type1[]="    `" . 'type_rent' . "` = '" . $value . "' ";
					
				} elseif ($name == 'object_usage') {
					
					//
					$e_val=explode('/', $value);
					foreach($e_val as $kk => $vv){
						if( strlen($vv)>2) {
						
						//物件用途
						if ($where_flag) {
							$where .= " WHERE ";
							$where_flag = false;
						} else {
							$where .= " AND ";
						}
						
						
						//$where .= "    `" . 'object_usage' . "` like '%" . $vv . "%' ";
						$__object_type2[] = "  `" . 'object_usage' . "` like '%" . trim($vv) . "%' ";
						
						}
					}
				}



				//屋況樓層
				if ($name == "windows") {
					//落地窗座向
					//if(is_array($value))
					$e_val=explode('/', $value);
					foreach($e_val as $kk => $vv){
						if(strlen($vv)>3){
							//echo strlen($vv);
							//echo '+';
							
							if ($where_flag) {
								$where .= " WHERE ";
								$where_flag = false;
							} else {
								$where .= " AND ";
							}
		
							//$where .=   "    `" . 'windows' . "` like '%" . $vv . "%' ";
							$__house_or1[]= "    `" . 'windows' . "` like '%" . trim($vv) . "%' ";
						}
					}
				} elseif ($name == "household_door") {
					//該戶座向
					//if(is_array($value))
					$e_val=explode('/', $value);
					foreach($e_val as $kk => $vv){
						if(strlen($vv)>3){
							if ($where_flag) {
								$where .= " WHERE ";
								$where_flag = false;
							} else {
								$where .= " AND ";
							}
	
							//$where .= "    `" . 'facing_the_household' . "` like '%" . $vv . "%' ";
							$__house_or2[]= "    `" . 'facing_the_household' . "` like '%" . trim($vv) . "%' ";
						}
					}
				} elseif ($name == "building_entrance") {
					//大樓座向
					//if(is_array($value))
					$e_val=explode('/', $value);
					foreach($e_val as $kk => $vv){
						if(strlen($vv)>3){
							if ($where_flag) {
								$where .= " WHERE ";
								$where_flag = false;
							} else {
								$where .= " AND ";
							}
		
							//$where .= "    `" . 'building_facing' . "` like '%" . $vv . "%' ";
							$__house_or3[]= "    `" . 'building_facing' . "` like '%" . trim($vv) . "%' ";
						}
					}
				} elseif ($name == 'floor') {
					//指定樓層
					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					//$where .= " (   `" . 'designated_floors1' . "` <= '" . $value . "' ";
					//$where .= " AND `" . 'designated_floors2' . "` >= '" . $value . "' )";
					
					$__house_and1[]= "  `" . 'designated_floors1' . "` <= '" . $value . "' ";								
					$__house_and1[]= "  `" . 'designated_floors2' . "` >= '" . $value . "' ";

				}elseif ($name == 'year_of_construction') {
					//屋齡
					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					//$where .= "    `" . 'year_of_construction' . "` <= '" . $value . "' ";
					$__house_and2[]= "    `" . 'year_of_construction' . "` <= '" . $value . "' ";
				}





				



				////////////////////////////////////////////////////////////////////////////

				if ($name == "sale_total") {

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					//$where .= " (   `" . 'total_budget1' . "` <= '" . $value . "' ";
					//$where .= " AND `" . 'total_budget2' . "` >= '" . $value . "' )";
					
					if($_type_rent){
						$__price1[]=	"  `" . 'total_budget1' . "` <= '" . $value . "' ";
						$__price1[]=	"  `" . 'total_budget2' . "` >= '" . $value . "' ";
					} 
					
					if($_type_sale){
						$__price1[]=	"  `" . 'total_budget1' . "` <= '" . $value . "' ";
						$__price1[]=    "  `" . 'total_budget2' . "` >= '" . $value . "' ";
					} 
					
					//$__price1[]=	" (   `" . 'total_budget1' . "` <= '" . $value . "' ".
					//			" AND `" . 'total_budget2' . "` >= '" . $value . "' )";
								
				} elseif ($name == 'house_building') {

					//$excerpt_array[] = "  `" . 'sections1' . "` like '%" . $value . "%'   ";
					//$excerpt_array[] = "  `" . 'sections2' . "` like '%" . $value . "%'  ";
					
					$__area_place1[]=	 "  `" . 'sections1' . "` like '%" . $value . "%'   ";
					$__area_place1[]=	 "  `" . 'sections2' . "` like '%" . $value . "%'   ";

				} elseif ($name == 'main_building_area') {
					
					/*
					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					$where .= " (    `" . 'indoor_area1' . "` <= '" . $value . "' ";
					$where .= " AND  `" . 'indoor_area2' . "` >= '" . $value . "' ) ";
					*/
					//$__area_number1[]=	" (    `" . 'indoor_area1' . "` <= '" . $value . "' ".
					//					" AND  `" . 'indoor_area2' . "` >= '" . $value . "' ) ";
					
				} elseif ($name == "stakeholders_land_area") {

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					//$where .= " (   `" . 'land_area1' . "` <= '" . $value . "' ";
					//$where .= " AND `" . 'land_area2' . "` >= '" . $value . "' )";
					
					$__area_number2[]=	"   `" . 'land_area1' . "` <= '" . $value . "' ";
					$__area_number2[]=  "   `" . 'land_area2' . "` >= '" . $value . "' ";

				} elseif ($name == "rent_rent_per_ping") {
					
					
					
					/*
					 * if($_type_rent){
						
						$__price2[]=	"    `" . 'budget_per_ping1' . "` <= '" . $value . "'    ";
						$__price2[]=	"    `" . 'budget_per_ping2' . "` >= '" . $value . "'    ";
					} 
					
					if($_type_sale){
					 */ 
						$__price2[]=	"    `" . 'budget_per_ping1' . "` <= '" . $value . "'    ";
						$__price2[]=	"    `" . 'budget_per_ping2' . "` >= '" . $value . "'    ";
					//}
					
					

				}elseif ($name == "sale_housing_unit_price") {
					
					
					/*
					if($_type_rent){
						
						$__price2[]=	"    `" . 'budget_per_ping1' . "` <= '" . $value . "'    ";
						$__price2[]=	"    `" . 'budget_per_ping2' . "` >= '" . $value . "'    ";
					} 
					
					if($_type_sale){
						*/
						$__price2[]=	"    `" . 'budget_per_ping1' . "` <= '" . $value . "'    ";
						$__price2[]=	"    `" . 'budget_per_ping2' . "` >= '" . $value . "'    ";
					//}
					
					

				} elseif ($name== "building_area") {

					$vvv = @floor($value);

					if ($where_flag) {

						$where .= " WHERE ";
						$where_flag = false;

					} else {

						$where .= " AND ";

					}
					
					//$where .= " (   `" . 'building_area1' . "` <= '" . $vvv . "' ";
					//$where .= " AND `" . 'building_area2' . "` >= '" . $vvv . "' ) ";
					//echo 'A/';
					$__area_number3[]="    `" . 'building_area1' . "` <= '" . $vvv . "' ";
					$__area_number3[]="    `" . 'building_area2' . "` >= '" . $vvv . "'  ";

				} elseif ($name == "area") {

					//$excerpt_array[] = " `" . 'key_areas1' . "` like '%" . $value . "%' ";
					//$excerpt_array[] = " `" . 'key_areas2' . "` like '%" . $value . "%' ";
					$__area_place2[]= " `" . 'key_areas1' . "` like '%" . $value . "%' ";
					$__area_place2[]= " `" . 'key_areas2' . "` like '%" . $value . "%' ";

				} elseif ($name == "building_name") {

					//$excerpt_array[] = "  `" . 'specify_building1' . "` like '%" . $value . "%' ";
					//$excerpt_array[] = "  `" . 'specify_building2' . "` like '%" . $value . "%' ";
					$__area_place3[] 	 = "  `" . 'specify_building1' . "` like '%" . $value . "%' ";
					$__area_place3[] 	 = "  `" . 'specify_building2' . "` like '%" . $value . "%' ";

				}

			}

		}

		
		$first_flag = true;
		if (count($excerpt_array) > 0) {
			foreach ($excerpt_array as $key => $val) {

				if ($first_flag) {
					$first_flag = false;
					if ($where_flag) {

						$where .= " WHERE ( ";
						$where_flag = false;
						$where .= $val;

					} else {

						$where .= " AND ( ";
						$where .= $val;
					}

				} else {

					$where .= ' OR ' . $val;

				}

				//echo '<font color=blue>'.$key.'=>'.$val.'</font>';

				if ((count($excerpt_array) - 1) == $key) {
					$where .= " ) ";
				}

			}
		}
		
		$collect=array();
		
	
		
		
		
		
		
		$collect[] = $this->collect_sql($__area_place1 , ' OR ' );
		$collect[] = $this->collect_sql($__area_place2 , ' OR ' );
		$collect[] = $this->collect_sql($__area_place3 , ' OR ' );
		
		
		$collect[] = $this->collect_sql($__area_number1, ' AND ');
		$collect[] = $this->collect_sql($__area_number2, ' AND ');
		$collect[] = $this->collect_sql($__area_number3, ' AND ');
		
		
		
		
		$collect[] = $this->collect_sql($__price1, ' AND ');
		//$collect[] = $this->collect_sql($__price2, ' AND ');
		
		
		
		$__sql__str='';
		$__sql__flag=true;
		
		//print_r($collect);
		foreach($collect as $coll=>$ect){
			
			if(strlen($ect)>2){
				//echo $ect.'<br>';
				if($__sql__flag ){
					$__sql__flag=false;
					$__sql__str.=$ect;		
				}else{
					$__sql__str.=" OR ".$ect;
				}
			}
			
		}
		
		
		
		$sql_schema = 'SELECT * FROM `h_demand` ' . $where;
		$new__sql_schema='';
		if(strlen($__sql__str) >3){
			 $new__sql_schema = 'SELECT * FROM `h_demand` WHERE ' . $__sql__str . " limit ".$_start_num .",". $load_count;
		}else{
			 $new__sql_schema = 'SELECT * FROM `h_demand`  '  . " limit ".$_start_num .",". $load_count;
		}
		
		
		return $new__sql_schema;
	}



	function collect_sql($data ,$type) {
		
		$_sql_str='';
		$_flag=true;
		
		
		
		if(count($data)>=1){		
			foreach($data as $da => $ta){
				
				if($_flag){
					
					$_flag=false;
					$_sql_str="( ".$ta;
					
				}else{
					
					$_sql_str.=$type;
					$_sql_str.=$ta;
					
				}	
				
			}
			
			$_sql_str.=' ) ';
		}
		
		return $_sql_str;
		
	}




	function demand_pair_object_sql($data , $_start_num , $load_count) {

		$where_flag = TRUE;

		$where = '';

		$excerpt_array = array();
		
		
		$__area_place1 			=	array();//區域－路段
		$__area_place2 			=	array();//區域－路段
		$__area_place3 			=	array();//區域－路段
		
		
		$__area_number1 			=	array();//面積
		$__area_number2 			=	array();//面積
		$__object_type_or1			=	array();
		$__object_type_or2			=	array();
		
		
		$__other1				=	array();
		$__other2				=	array();
		$__other3				=	array();
		$__other4				=	array();
		$__other5				=	array();
		
		$__price				=	array();
		
		$__house_and1			=	array();
		$__house_and2			=	array();
		
		$__house_or1				=	array();
		$__house_or2				=	array();
		$__house_or3				=	array();
		
		
		
		//print_r($data);
		
		$_type_rent = !empty($data["type_rent"])?$data["type_rent"]:'';
		$_type_sell = !empty($data["type_sell"])?$data["type_sell"]:'';
		
		
		
		foreach ($data as $name => $value) {

			if ($value != '' AND $value != '0' AND $value != '0.00') {
				//echo $name.'/'.$value;
				//物件類型
				if ($name == "type_sell") {
					//售

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " OR ";
					}

					$where .= "    `" . 'type_sale' . "` = '" . $value . "' ";
					$__object_type_or1[]= "    `" . 'type_sale' . "` = '" . $value . "' ";
				}
				if ($name == "type_rent") {
					//租

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " OR ";
					}

					$where .= "    `" . 'type_rent' . "` = '" . $value . "' ";
					$__object_type_or1[]= "    `" . 'type_rent' . "` = '" . $value . "' ";

				} elseif ($name == 'object_usage') {
					//print_r($value);
					//物件用途
					//if(is_array($value))
					$e_val=explode('/', $value);
					foreach($e_val as $kk => $vv){
						
						if(strlen($vv)>2){
							if ($where_flag) {
								$where .= " WHERE ";
								$where_flag = false;
							} else {
								$where .= " AND ";
							}
		
							//$where .= "    `" . 'object_usage' . "` like '%" . $vv . "%' ";
							$__object_type_or2[]= "    `" . 'object_usage' . "` like '%" . trim($vv) . "%' ";
						}
						
					}
				}

				//屋況樓層
				if ($name == "windows") {
					//落地窗座向
					//if(is_array($value))
					$e_val=explode('/', $value);
					foreach($e_val as $kk => $vv){
						if(strlen($vv)>3){
							if ($where_flag) {
								$where .= " WHERE ";
								$where_flag = false;
							} else {
								$where .= " OR ";
							}
		
							//$where .= "    `" . 'windows' . "` like '%" . $vv . "%' ";
							$__house_or1[]= "    `" . 'windows' . "` like '%" . trim($vv) . "%' ";
							
						}
					}
					
				} elseif ($name == "facing_the_household") {
					//該戶座向
					
					$e_val=explode('/', $value);
					foreach($e_val as $kk => $vv){
						if(strlen($vv)>3){
							if ($where_flag) {
								$where .= " WHERE ";
								$where_flag = false;
							} else {
								$where .= " OR ";
							}
		
							//$where .= "    `" . 'household_door' . "` like '%" . $vv . "%' ";
							$__house_or2[]="    `" . 'household_door' . "` like '%" . trim($vv) . "%' ";
						}
					}
				} elseif ($name == "building_facing") {
					//大樓座向
					if(strlen($value)>3)
					$e_val=explode('/', $value);
					foreach($e_val as $kk => $vv){
						if(strlen($vv)>3){
							if ($where_flag) {
								$where .= " WHERE ";
								$where_flag = false;
							} else {
								$where .= " OR ";
							}
		
							//$where .= "    `" . 'building_entrance' . "` like '%" . $vv . "%' ";
							$__house_or3[]="    `" . 'building_entrance' . "` like '%" . trim($vv) . "%' ";
						}
					}
				} elseif ($name == 'designated_floors1') {
					//指定樓層1
					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					$where .= "  `" . 'floor' . "` >= '" . $value . "' ";
					$__house_and1[]="  `" . 'floor' . "` >= '" . $value . "' ";

				} elseif ($name == 'designated_floors2') {
					//指定樓層2
					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					$where .= "  `" . 'floor' . "` <= '" . $value . "' ";
					$__house_and1[]="  `" . 'floor' . "` <= '" . $value . "' ";

				}elseif ($name == 'year_of_construction1') {
					//屋齡
					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					$where .= "    `" . 'year_of_construction' . "` >= '" . $value . "' ";
					$__house_and2[]="    `" . 'year_of_construction' . "` >= '" . $value . "' ";
					
				}elseif ($name == 'year_of_construction2') {
					//屋齡
					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					$where .= "    `" . 'year_of_construction' . "` <= '" . $value . "' ";
					$__house_and2[]="    `" . 'year_of_construction' . "` <= '" . $value . "' ";
				}
				
				
				

			

				
				/////////////////////////////////////////////////////////////////////////
				if ($name == "total_budget1") {

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					$where .= "  `" . 'sale_total' . "` >= '" . $value . "' ";
					
					//租
					if($_type_rent){
						$__price[]= " `" . 'rent_total' . "` >= '" . $value . "' ";						
					} 
										
					//售
					if($_type_sell){
						$__price[]= " `" . 'sale_total' . "` >= '" . $value . "' ";
					} 
					
					if(empty($_type_rent) AND empty($_type_sell) ){
						
						$__price[]= " `" . 'sale_total' . "` >= '" . $value . "' ";
						
					}

				} elseif ($name == "total_budget2") {

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					
					//租
					if($_type_rent){
						$__price[]= " `" . 'rent_total' . "` <= '" . $value . "' ";
					} 				
					//售
					if($_type_sell){
						$__price[]= " `" . 'sale_total' . "` <= '" . $value . "' ";
					} 
					
					

				} elseif ($name == 'sections1') {

					$excerpt_array[] = "  `" . 'house_building' . "` like '%" . $value . "%' ";
					$__area_place1[]= "  `" . 'house_building' . "` like '%" . $value . "%' ";
					
				} elseif ($name == 'sections2') {

					$excerpt_array[] = "  `" . 'house_building' . "` like '%" . $value . "%' ";
					$__area_place1[]= "  `" . 'house_building' . "` like '%" . $value . "%' ";
					
				} elseif ($name == 'indoor_area1') {

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					//$where .= "  `" . 'main_building_area' . "` >= '" . $value . "' ";
					//$__area_number[]= "  `" . 'main_building_area' . "` >= '" . $value . "' ";
					
				} elseif ($name == 'indoor_area2') {

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					//$where .= "  `" . 'main_building_area' . "` <= '" . $value . "' ";
					//$__area_number[]= "  `" . 'main_building_area' . "` <= '" . $value . "' ";
					
				} elseif ($name == "land_area1") {

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					$where .= "  `" . 'stakeholders_land_area' . "` >= '" . $value . "' ";
					$__area_number1[]= "  `" . 'stakeholders_land_area' . "` >= '" . $value . "' ";

				} elseif ($name == "land_area2") {

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					$where .= "  `" . 'stakeholders_land_area' . "` <= '" . $value . "' ";
					$__area_number1[]= "  `" . 'stakeholders_land_area' . "` <= '" . $value . "' ";
					
					
				} elseif ($name == "budget_per_ping1") {

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					//$where .= "  `" . 'sale_land_unit_price' . "` >= '" . $value . "' ";
					//$__price[]="  `" . 'sale_land_unit_price' . "` >= '" . $value . "' ";
					
					//租
					if($_type_rent){
						$__price[]= " `" . 'rent_rent_per_ping' . "` >= '" . ((int)$value) . "' ";
					} 				
					//售
					if($_type_sell){
						$__price[]= " `" . 'sale_housing_unit_price' . "` >= '" . ((int)$value) . "' ";
					}
					
				} elseif ($name == "budget_per_ping2") {

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					//$where .= "  `" . 'sale_land_unit_price' . "` <= '" . $value . "' ";
					//$__price[]="  `" . 'sale_land_unit_price' . "` <= '" . $value . "' ";
					
					//租
					if($_type_rent){
						$__price[]= " `" . 'rent_rent_per_ping' . "` <= '" . $value . "' ";
					} 				
					//售
					if($_type_sell){
						$__price[]= " `" . 'sale_housing_unit_price' . "` <= '" . $value . "' ";
					}
					
					
				} elseif ($name == "building_area1") {

					$vvv = @floor($value);

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					$where .= "  `" . 'building_area' . "` >= '" . $vvv . "' ";
					$__area_number2[]= "  `" . 'building_area' . "` >= '" . $vvv . "' ";

				} elseif ($name == "building_area2") {

					$vvv2 = floor($value);

					if ($where_flag) {
						$where .= " WHERE ";
						$where_flag = false;
					} else {
						$where .= " AND ";
					}

					$where .= "  `" . 'building_area' . "` <= '" . $vvv2 . "' ";
					$__area_number2[]= "  `" . 'building_area' . "` <= '" . $vvv2 . "' ";

				} elseif ($name == "key_areas1") {

					//$excerpt_array[] = "  `" . 'area' . "` like '%" . $value . "%' ";				
					$__area_place2[]= "  `" . 'area' . "` like '%" . $value . "%' ";

				} elseif ($name == "key_areas2") {

					//$excerpt_array[] = "  `" . 'area' . "` like '%" . $value . "%' ";
					$__area_place2[]= "  `" . 'area' . "` like '%" . $value . "%' ";

				} elseif ($name == "specify_building1") {

					//$excerpt_array[] = "  `" . 'building_name' . "` like '%" . $value . "%' ";
					$__area_place3[]= "  `" . 'building_name' . "` like '%" . $value . "%' ";

				} elseif ($name == "specify_building2") {

					//$excerpt_array[] = "  `" . 'building_name' . "` like '%" . $value . "%' ";
					$__area_place3[]= "  `" . 'building_name' . "` like '%" . $value . "%' ";
				}

			}
		}

		$first_flag = true;
		if (count($excerpt_array) > 0) {
			foreach ($excerpt_array as $key => $val) {

				if ($first_flag) {
					$first_flag = false;
					if ($where_flag) {

						$where .= " WHERE ( ";
						$where_flag = false;
						$where .= $val;

					} else {

						$where .= " AND ( ";
						$where .= $val;
					}

				} else {

					$where .= ' OR ' . $val;

				}

				

				if ((count($excerpt_array) - 1) == $key) {
					$where .= " ) ";
				}

			}
		}
		
		
		$collect=array();
		$collect[] = $this->collect_sql($__area_place1 , ' OR ' );
		$collect[] = $this->collect_sql($__area_place2 , ' OR ' );
		$collect[] = $this->collect_sql($__area_place3 , ' OR ' );
		
		//$__area_number2
		
		$collect[] = $this->collect_sql($__area_number2, ' AND ');
		
		
		
		$collect[] = $this->collect_sql($__price, ' AND ');
		
		
		$__sql__str='';
		$__sql__flag=true;
		
		//print_r($collect);
		foreach($collect as $coll=>$ect){
			
			if(strlen($ect)>2){
				
				if($__sql__flag ){
					$__sql__flag=false;
					$__sql__str.=$ect;		
				}else{
					$__sql__str.=" OR ".$ect;
				}
			}
			
		}
		//echo $__sql__str;
		
		$new_sql_schema=array();
		
		if(strlen($__sql__str)>2 ){
			 $new_sql_schema[0] = 'SELECT * FROM `h_object` WHERE ' . $__sql__str." limit ".$_start_num .",". $load_count;
		}else{
			$new_sql_schema[0] = 'SELECT * FROM `h_object`   ' ." limit ".$_start_num .",". $load_count;
		}	
		
		
		
		if(strlen($__sql__str)>3 ){
			  $new_sql_schema[1] = 'SELECT * FROM `h_market_research`  WHERE  ' . $__sql__str." limit ".$_start_num .",". $load_count;
		}else{
			$new_sql_schema[1] = 'SELECT * FROM `h_market_research`   ' ." limit ".$_start_num .",". $load_count;
		}
		
		
		
		return $new_sql_schema;
	}


	

}
